package com.ruoyi.literature.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.literature.domain.Literature;
import com.ruoyi.literature.service.ILiteratureService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 文献Controller
 * 
 * @author ruoyi
 * @date 2025-02-24
 */
@RestController
@RequestMapping("/literature/literature")
public class LiteratureController extends BaseController
{
    @Autowired
    private ILiteratureService literatureService;

    /**
     * 查询文献列表
     */
    @PreAuthorize("@ss.hasPermi('literature:literature:list')")
    @GetMapping("/list")
    public TableDataInfo list(Literature literature)
    {
        startPage();
        List<Literature> list = literatureService.selectLiteratureList(literature);
        return getDataTable(list);
    }

    /**
     * 导出文献列表
     */
    @PreAuthorize("@ss.hasPermi('literature:literature:export')")
    @Log(title = "文献", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Literature literature)
    {
        List<Literature> list = literatureService.selectLiteratureList(literature);
        ExcelUtil<Literature> util = new ExcelUtil<Literature>(Literature.class);
        util.exportExcel(response, list, "文献数据");
    }

    /**
     * 获取文献详细信息
     */
    @PreAuthorize("@ss.hasPermi('literature:literature:query')")
    @GetMapping(value = "/{literatureId}")
    public AjaxResult getInfo(@PathVariable("literatureId") Long literatureId)
    {
        return success(literatureService.selectLiteratureByLiteratureId(literatureId));
    }

    /**
     * 新增文献
     */
    @PreAuthorize("@ss.hasPermi('literature:literature:add')")
    @Log(title = "文献", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Literature literature)
    {
        return toAjax(literatureService.insertLiterature(literature));
    }

    /**
     * 修改文献
     */
    @PreAuthorize("@ss.hasPermi('literature:literature:edit')")
    @Log(title = "文献", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Literature literature)
    {
        return toAjax(literatureService.updateLiterature(literature));
    }

    /**
     * 删除文献
     */
    @PreAuthorize("@ss.hasPermi('literature:literature:remove')")
    @Log(title = "文献", businessType = BusinessType.DELETE)
	@DeleteMapping("/{literatureIds}")
    public AjaxResult remove(@PathVariable Long[] literatureIds)
    {
        return toAjax(literatureService.deleteLiteratureByLiteratureIds(literatureIds));
    }
}
